//
//  RepairHistoryCell.m
//  智慧小区
//
//  Created by lab603 on 15/6/30.
//  Copyright (c) 2015年 Dreamsoul. All rights reserved.
//

#import "RepairHistoryCell.h"
#import "RepairFrame.h"
#import "Repair.h"
#define cellBorder 10
@interface RepairHistoryCell()
//时间Label
@property (nonatomic,weak)UILabel *timeLabel;
//状态Label
@property (nonatomic,weak)UILabel *statusLabel;
//分隔线top
@property (nonatomic,weak)UIImageView *separatorTop;
//类别Icon
@property (nonatomic,weak)UIImageView *typeIcon;
//维修类别
@property (nonatomic,weak)UILabel *repairType;
//维修地址(针对公共报修)
@property (nonatomic,weak)UILabel *repairAddress;
//维修情况
@property (nonatomic,weak)UILabel *repairDetail;
//分割线bottom
@property (nonatomic,weak)UIImageView *separatorBottom;
//评价按钮
@property (nonatomic,weak)UIButton *evaluateBtn;
@end

@implementation RepairHistoryCell
+ (instancetype)cellWithTableView:(UITableView *)tableview{
    static NSString *ID = @"repairCell";
    RepairHistoryCell * cell = [tableview dequeueReusableCellWithIdentifier:ID];
    if (cell==nil) {
        cell = [[RepairHistoryCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectedBackgroundView = [[UIView alloc] init];
        //时间Label
        UILabel *timeLabel = [[UILabel alloc] init];
        timeLabel.textColor = [UIColor grayColor];
        timeLabel.backgroundColor = [UIColor clearColor];
        timeLabel.font = [UIFont systemFontOfSize:13.0];
        [self.contentView addSubview:timeLabel];
        self.timeLabel = timeLabel;
        //状态
        UILabel *statusLabel = [[UILabel alloc] init];
        statusLabel.textColor = [UIColor grayColor];
        statusLabel.backgroundColor = [UIColor clearColor];
        statusLabel.font = [UIFont systemFontOfSize:13.0];
        [self.contentView addSubview:statusLabel];
        self.statusLabel = statusLabel;
        //分割线top
        UIImageView *separatorTop = [[UIImageView alloc] init];
        separatorTop.backgroundColor = App_Separator_Color;
        [self.contentView addSubview:separatorTop];
        self.separatorTop = separatorTop;
        //类别头像
        UIImageView *typeIcon = [[UIImageView alloc] init];
        [self.contentView addSubview:typeIcon];
        self.typeIcon = typeIcon;
        //维修类别
        UILabel *repairType = [[UILabel alloc] init];
        repairType.textColor = [UIColor blackColor];
        repairType.backgroundColor = [UIColor clearColor];
        repairType.font = [UIFont systemFontOfSize:16.0];
        [self.contentView addSubview:repairType];
        self.repairType = repairType;
        //维修情况
        UILabel *repairDetail = [[UILabel alloc] init];
        repairDetail.textColor = [UIColor grayColor];
        repairDetail.backgroundColor = [UIColor clearColor];
        repairDetail.font = [UIFont systemFontOfSize:13.0];
        [self.contentView addSubview:repairDetail];
        self.repairDetail = repairDetail;
        //分割线bottom
        UIImageView *separatorBottom = [[UIImageView alloc] init];
        separatorBottom.backgroundColor = App_Separator_Color;
        [self.contentView addSubview:separatorBottom];
        self.separatorBottom = separatorBottom;
        //评价按钮
        UIButton *evaluateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [evaluateBtn setTitleColor:APP_THEME_COLOR forState:UIControlStateNormal];
        [evaluateBtn setTitle:@"评价" forState:UIControlStateNormal];
        evaluateBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [evaluateBtn addTarget:self action:@selector(evaluate) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview: evaluateBtn];
        self.evaluateBtn = evaluateBtn;
        
    }
    return self;
}
- (void)setRepairFrame:(RepairFrame *)repairFrame{
    _repairFrame = repairFrame;
    Repair *repair = repairFrame.repair;
    //给控件的Frame赋值
    self.timeLabel.frame = repairFrame.timeLabelF;
    self.statusLabel.frame = repairFrame.statusLabelF;
    self.separatorTop.frame = repairFrame.separatorTopF;
    self.typeIcon.frame = repairFrame.typeIconF;
    self.repairType.frame = repairFrame.repairTypeF;
    self.repairDetail.frame = repairFrame.repairDetailF;
    self.separatorBottom.frame = repairFrame.separatorBottomF;
    self.evaluateBtn.frame = repairFrame.evaluateBtnF;
    if (repair.isFixed!=1) {
        self.separatorBottom.hidden = YES;
        self.evaluateBtn.hidden = YES;
    }else{
        self.separatorBottom.hidden = NO;
        self.evaluateBtn.hidden = NO;
    }
    //给控件的值赋值
    self.timeLabel.text = repair.timeOne;
    NSString *status = nil;
    if (repair.isFixed==0) {
        status = @"已提交";
    }else if (repair.isFixed==1){
        status = @"已完成";
    }else if (repair.isFixed==2){
        status = @"处理中";
    }
    self.statusLabel.text = status;
    NSString *typeString = @"";
    NSString *imageString = @"";
    switch (repair.type) {
        case 1:
            typeString = @"给排水维修";
            imageString = @"paishuibaoxiu";
            break;
        case 2:
            typeString = @"室内电气维修";
            imageString = @"dianqibaoxiu";
            break;
        case 3:
            typeString = @"门窗维修";
            imageString = @"menchuangbaoxiu";
            break;
        case 4:
            typeString = @"保洁服务";
            imageString = @"baojiefuwu";
            break;
        case 5:
            typeString = @"其他";
            imageString = @"qita";
            break;
    }
        self.typeIcon.image = [UIImage imageNamed:imageString];
        self.repairType.text = typeString;
        self.repairDetail.text = repair.texts;
}
/**
 *  点击了评价按钮
 */
- (void)evaluate{
    
}
- (void)setFrame:(CGRect)frame
{
    frame.origin.y += cellBorder;
    frame.size.height -= cellBorder;
    [super setFrame:frame];
}
@end
